package cartFilter;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "LoginServlet", value = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
            response.setContentType("text/html;charset=utf-8");
        if (username.equals("zs") && password.equals("123")) {
            System.out.println("登录成功");
            session.setAttribute("username", "zs");
            response.getWriter().println("登录成功");
            response.setHeader("refresh", "2,cart.html");
        }else {
            response.getWriter().println("登录失败。。。。");
        }
    }
}
